package com.imooc.job;

import java.util.concurrent.TimeUnit;

import net.javacrumbs.shedlock.spring.annotation.SchedulerLock;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class SimpleJob {
    private static final Logger logger = LoggerFactory.getLogger(SimpleJob.class);

    @Scheduled(cron = "0 */1 * * * ?")
    public void job1() {
        logger.info("time=" + DateTime.now().toString("YYYY-MM-dd HH:mm:ss") + " do job1...");
    }

    @Scheduled(cron = "0 */1 * * * ?")
    @SchedulerLock(name = "lock-job2", lockAtMostFor = "10s")
    public void job2() throws InterruptedException {
        logger.info("time=" + DateTime.now().toString("YYYY-MM-dd HH:mm:ss") + " do job2...");
        TimeUnit.SECONDS.sleep(1L);
    }
}
